<template>
  <el-dialog
    v-model="centerDialogVisible"
    width="40%"
    align-center
    color="white"
    style="background-color: #7a7e8473"
  >
    <h1 style="color: white">更新图书信息</h1>
    <div style="display: inline; color: white">
      书籍名称：<el-input
        type="text"
        placeholder="请填写书籍名"
        v-model="bookname"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍分类：<el-input
        type="text"
        placeholder="请填写书籍分类"
        v-model="categoryId"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍封面：<el-input
        type="text"
        placeholder="请填写书籍封面"
        v-model="cover"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍介绍：<el-input
        type="text"
        placeholder="请填写书籍介绍"
        v-model="info"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍价格：
      <el-input
        type="text"
        placeholder="请填写书籍价格"
        v-model="inPrice"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍数量：
      <el-input
        type="text"
        placeholder="请填写书籍入货数量"
        v-model="quantity"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍折扣：
      <el-input
        type="text"
        placeholder="请填写书籍入货折扣"
        v-model="discount"
        style="display: inline"
      ></el-input>
    </div>
    <br />
    <div style="display: inline; color: white">
      书籍城市：<el-input
        type="text"
        placeholder="请填写书籍城市"
        v-model="city"
        style="display: inline"
      ></el-input>
    </div>
    <br />

    <div style="display: inline; color: white">
      书籍是否为新书：<el-input
        type="text"
        placeholder="请填写书籍是否为新书（填写1为新书，0为旧书）"
        v-model="newbook"
        style="display: inline"
      ></el-input>
    </div>

    <template #footer>
      <span class="dialog-footer">
        <el-button
          @click="centerDialogVisible = false"
          style="background-color: rgb(57 175 191 / 48%); color: white"
          >取消</el-button
        >
        <el-button type=" " class="buy" @click="updatebook()" v-if="total != 0">
          确认
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
  <script>
export default {
  name: "UpdateBook",
  data() {
    return {
      centerDialogVisible: false,
      bookId: 0,
      bookname: "",
      categoryId: 0,
      cover: "",
      info: "",
      inPrice: 0,
      discount: 0,
      quantity: 0,
      city: "",
      newbook: 0,
    };
  },
  methods: {
    //         addbook(){
    //             var data=new FormData()
    //             data.append('bookname',this.bookname)
    //             data.append('categoryId',this.categoryId)
    //             data.append('cover',this.cover)
    //             data.append('info',this.info)
    //             data.append('inPrice',this.inPrice)
    //             data.append('quantity',this.quantity)
    //             data.append('city',this.city)
    //             data.append('newbook',this.newbook)
    //             this.$axios.post('/addbook',data).then(resp=>{
    // if(resp.data.code==200){
    //     this.$message({
    //         message: "添加成功",
    //         type: "success",
    //       });
    //       this.centerDialogVisible=false
    //       this.$parent.loadbookslist();
    // }
    //             })
    //         }
    updatebook() {
      var data = new FormData();
      data.append("bookname", this.bookname);
      data.append("categoryId", this.categoryId);
      data.append("cover", this.cover);
      data.append("info", this.info);
      data.append("inPrice", this.inPrice);
      data.append("quantity", this.quantity);
      data.append("city", this.city);
      data.append("newbook", this.newbook);
      data.append("discount", this.discount);
      data.append("bookId", this.bookId);
      this.$axios.post("/updatebook", data).then((resp) => {
        this.$message({
          message: "更新成功",
          type: "success",
        });
        this.$parent.loadbookslist();
      });

      this.centerDialogVisible = false;
    },
  },
};
</script>